<?php $this->load->view(TEMPLATE_NAME.'/admin/header');?>
<?php $this->load->view(TEMPLATE_NAME.'/admin/side_left');?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url()?>xhtml/admin/css/tia-admin.css" />
<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url()?>xhtml/admin/css/tia.css" />
<script type="text/javascript" src="<?php echo base_url()?>js/jquery-1.4.2.js"></script>
<script src="<?php echo base_url(); ?>js/ajaxfileupload.js"></script>
<script src="<?php echo base_url(); ?>js/si.files.js"></script>
<style type="text/css" title="text/css">
.SI-FILES-STYLIZED label.cabinet
{
    width: 100px;
    height: 28px;
    background: url(<?php echo base_url()?>image/select_ads.jpg) 0 0 no-repeat;

    display: block;
    overflow: hidden;
    cursor: pointer;
}

.SI-FILES-STYLIZED label.cabinet input.file
{
    position: relative;
    height: 100%;
    width: auto;
    opacity: 0;
    -moz-opacity: 0;
    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
}
</style>
<script type="text/javascript">
    SI.Files.stylizeAll();       
$(document).ready(function(){
    $('#show_item').change(function(){
        //alert($('#show_item').val());
        $.post("<?php echo site_url('json_request/get_ads')?>", {items: $('#show_item').val() }, function(data){
                var all_list = '';
                var s;
                $.each(data, function(i, list){
                    //all_list += '<li onClick="fill(\''+list.name+'\');">'+list.name+'</li>';
                    s = i + 1;
                    all_list += '<p class="f14 purple">Item '+ s +'</p><hr />'
                        + '<div class="wright wrightlong">'
                        + '<div class="addfoto">'
                        +    '<div class="labelf">'
                        +        '<p class="f13">Test Message: <sup>*</sup><br /><br /><br /><br />'
                        +        'URL <sup>*</sup><br /><br /><br />'
                        +        'ALT Tag <sup>*</sup></p><br />'
                        <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
                        +            '<input name="image_'+ s +'" class="file" type="file" id="image_'+ s +'" onchange="return ajaxFileUpload(this);"/>'
                        <?php else:  ?>
                        +        '<label class="cabinet">'
                        +            '<input name="image_'+ s +'" class="file" type="file" id="image_'+ s +'" onchange="return ajaxFileUpload(this);"/>'
                        +        '</label>'
                        <?php endif;?>                        
                        +    '</div>'
                        +    '<div class="fotor" style="position:relative;" >'
                        +        '<textarea class="h60" name="message[]">'+list.message+'</textarea><br />'
                        +        '<input type="text" name="url[]" value="'+list.url+'" /><br />'
                        +        '<input type="text" name="alt[]" value="'+list.alt_tag+'" /><br />'
                        +        '<img id="loading_'+ s +'" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:150px;top:310px" />'
                        +        '<div class="newimg" id="img_'+ s +'">'
                        +        '<img src="<?php echo base_url();?>uploads/landing_ads/thumb/'+list.image+'" width="385" height="320" />'
                        +        '<input name="upload[]" type="hidden" value="'+list.image+'">'                
                        +        '</div>'
                        +    '</div>'
                        +    '<div class="clear"></div>'
                        + '</div>'
                        + '</div>'
                });
                //alert(data.length);
                //alert($('#show_item').val());
                var total = $('#show_item').val();
                if((data != false) && (data.length != total)){
                    total_loop = total - data.length;
                }else{
                    total_loop = total;
                }
                
                var first_number = data.length + 1;
                if((data != false)) {                    
                    //alert(all_list);
                    for (i= first_number; i<= total;i++){
                        all_list += '<p class="f14 purple">Item '+i+'</p><hr />'
                        + '<div class="wright wrightlong">'
                        + '<div class="addfoto">'
                        +    '<div class="labelf">'
                        +        '<p class="f13">Test Message: <sup>*</sup><br /><br /><br /><br />'
                        +        'URL <sup>*</sup><br /><br /><br />'
                        +        'ALT Tag <sup>*</sup></p><br />'
                        <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
                        +            '<input name="image_'+i+'" class="file" type="file" id="image_'+i+'" onchange="return ajaxFileUpload(this);"/>'
                        <?php else:  ?>
                        +        '<label class="cabinet">'
                        +            '<input name="image_'+i+'" class="file" type="file" id="image_'+i+'" onchange="return ajaxFileUpload(this);"/>'
                        +        '</label>'
                        <?php endif;?>                        
                        +    '</div>'
                        +    '<div class="fotor" style="position:relative;" >'
                        +        '<textarea class="h60" name="message[]"></textarea><br />'
                        +        '<input type="text" name="url[]" value="" /><br />'
                        +        '<input type="text" name="alt[]" value="" /><br />'
                        +        '<img id="loading_'+i+'" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:150px;top:310px" />'
                        +        '<div class="newimg" id="img_'+i+'">'                
                        +        '</div>'
                        +    '</div>'
                        +    '<div class="clear"></div>'
                        + '</div>'
                        + '</div>'
                    } 
                }else{
                    for (a= 1; a <= total; a++){
                        all_list += '<p class="f14 purple">Item '+a+'</p><hr />'
                        + '<div class="wright wrightlong">'
                        + '<div class="addfoto">'
                        +    '<div class="labelf">'
                        +        '<p class="f13">Test Message: <sup>*</sup><br /><br /><br /><br />'
                        +        'URL <sup>*</sup><br /><br /><br />'
                        +        'ALT Tag <sup>*</sup></p><br />'                        
                        <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
                        +            '<input name="image_'+a+'" class="file" type="file" id="image_'+a+'" onchange="return ajaxFileUpload(this);"/>'
                        <?php else:  ?>
                        +        '<label class="cabinet">'
                        +            '<input name="image_'+a+'" class="file" type="file" id="image_'+a+'" onchange="return ajaxFileUpload(this);"/>'
                        +        '</label>'
                        <?php endif;?>                        
                        +    '</div>'
                        +    '<div class="fotor" style="position:relative;" >'
                        +        '<textarea class="h60" name="message[]"></textarea><br />'
                        +        '<input type="text" name="url[]" value="" /><br />'
                        +        '<input type="text" name="alt[]" value="" /><br />'
                        +        '<img id="loading_'+a+'" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:150px;top:310px" />'
                        +        '<div class="newimg" id="img_'+a+'">'                
                        +        '</div>'
                        +    '</div>'
                        +    '<div class="clear"></div>'
                        + '</div>'
                        + '</div>'
                    }
                }
                $('#list_ads').html('');
                $('#list_ads').html(all_list);
                //alert(data);
            }, "json");
    });        
});
function ajaxFileUpload(get_this){
    var this_id = get_this.id.split('_');
    var div_load = "#loading_" + this_id[1];
     
    $(div_load)
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
        $(this).unbind("ajaxStart");
    });    
    
    var img = '#img_' + this_id[1];
    $.ajaxFileUpload({
        url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/landing_ads/network/ads')?>/file/'+get_this.id,
        secureuri:false,       
        fileElementId: get_this.id,
        dataType: 'json',
        success: function (data, status){
            if(typeof(data.error) != 'undefined'){
                if(data.error != ''){                    
                    $(img).html(data.error);
                }else{                        
                    $(img).html('<img src="<?php echo base_url();?>uploads/landing_ads/thumb/'+data.msg+'" width="385" height="320" />'
                    +'<input type="hidden" name="upload[]" value="'+data.msg +'">');
                }
            }
        },
        error: function (data, status, e){
            $(span).html(e);
        }
    });
}
</script> 
<div class="page noright adminpage">
<h5 class="purple">NETWORKS (<?php echo $total_network?>)</h5>
<hr /><?php echo form_open_multipart('admin/landing_ads')?>
<label class="f14">Items:</label>
<select name="show_item" class="sh" id="show_item">
<?php for($a=1; $a <= 10; $a++){ ?>
<option value="<?php echo $a?>" <?php if((!empty($count)) && ($a == $count)){?> selected="selected" <?php }?>><?php echo $a?> items</option> 
<?php } ?>
</select> 
<hr />
<div id="list_ads">
    <?php if(!empty($ads_list)){
        $i = 1;
        foreach($ads_list as $ads){?>
    <p class="f14 purple">Item <?php echo $i;?></p>
    <hr />
    <div class="wright wrightlong">
        <div class="addfoto">
            <div class="labelf">
                <p class="f13">Test Message: <sup>*</sup><br /><br /><br /><br />
                URL <sup>*</sup><br /><br /><br />
                ALT Tag <sup>*</sup></p><br />                
                <!-- ie show button -->
                <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
                    <input name="image_<?php echo $i;?>" class="file" type="file" id="image_<?php echo $i;?>" onchange="return ajaxFileUpload(this);"/>
                <?php else:  ?>
                <label class="cabinet">
                    <input name="image_<?php echo $i;?>" class="file" type="file" id="image_<?php echo $i;?>" onchange="return ajaxFileUpload(this);"/>
                </label>
                <?php endif;?>
            </div><!-- labelf -->
            <div class="fotor" style="position:relative;" >
                <textarea class="h60" name="message[]"><?php echo $ads['message']?></textarea><br />
                <input type="text" name="url[]" value="<?php echo $ads['url']?>" /><br />
                <input type="text" name="alt[]" value="<?php echo $ads['alt_tag']?>" /><br />
                <img id="loading_<?php echo $i;?>" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:150px;top:310px" />
                <div class="newimg" id="img_<?php echo $i;?>">
                    <img src="<?php echo base_url();?>uploads/landing_ads/thumb/<?php echo $ads['image']?>" width="385" height="320" />
                    <input type="hidden" name="upload[]" value="<?php echo $ads['image']?>" >               
                </div><!-- newimg -->
            </div><!-- fotor -->
            <div class="clear"></div>
        </div><!-- addfoto -->
    </div><!--wright-->
    <?php $i++; } }else{ ?>
    <p class="f14 purple">Item 1</p>
    <hr />
    <div class="wright wrightlong">
        <div class="addfoto">
            <div class="labelf">
                <p class="f13">Test Message: <sup>*</sup><br /><br /><br /><br />
                URL <sup>*</sup><br /><br /><br />
                ALT Tag <sup>*</sup></p><br />          
                <!-- ie show button -->
                <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
                    <input name="image_1" class="file" type="file" id="image_1" onchange="return ajaxFileUpload(this);"/>
                <?php else:  ?>
                <label class="cabinet">
                    <input name="image_1" class="file" type="file" id="image_1" onchange="return ajaxFileUpload(this);"/>
                </label>
                <?php endif;?>
            </div><!-- labelf -->
            <div class="fotor" style="position:relative;" >
                <textarea class="h60" name="message[]"></textarea><br />
                <input type="text" name="url[]" value="" /><br />
                <input type="text" name="alt[]" value="" /><br />
                <img id="loading_1" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:150px;top:310px" />
                <div class="newimg" id="img_1">                                   
                </div><!-- newimg -->
            </div><!-- fotor -->
            <div class="clear"></div>
        </div><!-- addfoto -->
    </div><!--wright-->
    <?php } ?>
</div><!--list_ads-->
<hr />
    <div class="formstep">
    <?php
    $form_button = array(
    'type'=>'submit',
    'name'=>'submit',
    'value'=>'submit',    
    'content'=>'Submit',
    );
    echo form_button($form_button);
    echo form_close(); ?>
    </div>
</div><!-- page -->
<?php $this->load->view(TEMPLATE_NAME.'/admin/footer');?>